Repository navigation
fix(lab-ops-hub): validate the container crawler response shape before archiving or binding (#7018) - #7023
Merged
Conversation
…e archiving or binding (#7018) crawlWithContainer returned res.json() under a cast; the crawl route archived the spread result to R2 and bound its fields into the crawls INSERT unvalidated. A JSON null body 500d after the archive write, a JSON string stored an all-null row reported as success, and wrong-typed fields bound as-is — and the designed Worker fallback never triggered, because nothing threw until the damage was done. parseCrawlResult in lib.ts now validates the cross-service response (plain object; string title/excerpt/text, finite-number links/status_code when present). A malformed result throws in crawlWithContainer, so the route falls back to the Worker crawler with container_error set, like any other container failure. Tests: 3 new lib.test.ts cases (well-formed passthrough, non-object bodies, wrong-typed fields); TS suite 106/106 on the branch; the new tests fail against pre-fix lib.ts. Probe replay (~/git/fleet/probe-labops-crawl, real index.ts): control unchanged, all malformed shapes now fall back with sane binds. (Python suite: 2 import errors from a missing idna module, identical on clean main — pre-existing baseline.)
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 3 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7018
crawlWithContainerreturnedres.json()under a type cast, and the/api/crawlroute archived the spread result to R2 and bound its fields into thecrawlsINSERT unvalidated. Verified pre-fix with the realindex.ts(probe~/git/fleet/probe-labops-crawl, md5-checked copy, only the two platform imports stubbed):null→ 500 rawTypeErroronresult.title, after the R2 archive was already written (orphan archive, no crawls row)ok:true, crawls row with all fields null, archive body spread by character index ({"0":"h",…})linksas an object → 500 raw D1 bind TypeError, again after the archive writetitle: 123,links: "3",status_code: "200") → bound as-isFix:
parseCrawlResultinsrc/lib.tsvalidates the cross-service response (plain non-null/non-array object;title/excerpt/textstrings andlinks/status_codefinite numbers when present) andcrawlWithContainerthrows on a malformed result, so the route's existing catch falls back to the Worker crawler withcontainer_errorset — the same treatment as any other container failure. No side effects happen before validation.Verification (laptop):
node --test "test/**/*.test.ts": 106/106 on the branch (3 newparseCrawlResulttests); the new tests fail against pre-fixlib.tssource: "worker-fallback"with a shape-namingcontainer_errorand sane bindsidnamodule missing in that env), identical on clean main — pre-existing baselinetsc --noEmitnot run:npm ciin the worktree hung with no output for ~9 min and was killed; the suite above executes the real TS via type stripping. CI will typecheck per repo policy if configured.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.